const router = require('koa-router')()
const path = require('path');
const fs = require('fs');



/**
 * 静态首页入口 get 接口
 */
router.get('/', async (ctx, next) => {
  ctx.type = 'html'
  const rootPath = path.join(__dirname,'../');//取得根目录绝对路径
  const pathUrl = path.join(rootPath,'/public/html/index.html')
  ctx.body = fs.createReadStream(pathUrl);
})

/**
 * 静态上传页入口 get 接口
 */
router.get('/uploadPage',async(ctx,next)=>{
  ctx.type = 'html'
  const pathUlr = path.join(__dirname,'../public/html/upload.html')
  ctx.body = fs.createReadStream(pathUlr);
})

/**
 * 静态下载页入口 get 接口
 */
router.get('/downloadPage',(ctx,next)=>{
  ctx.type = 'html';
  const pathUrl = path.join(__dirname,'../public/html/download.html')
  ctx.body =fs.createReadStream(pathUrl);
})


//-------------------------------------- 预留及test ---------------------------//
router.get('/string', async (ctx, next) => {
  ctx.body = 'koa2 string'
})

router.get('/json', async (ctx, next) => {
  ctx.body = {
    title: 'koa2 json'
  }
})

module.exports = router
